﻿using System.IO;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CustomTasks.Test
{
    [TestClass]
    public class StripCommentsTest
    {
        private readonly StripComments _stripComments = new StripComments();

        [TestMethod]
        public void TestThatErrorThrowsWhenFileNotFound()
        {
            _stripComments.InputFilePath =
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Substring(6);
            _stripComments.InputFileName = "Web.configs";

            _stripComments.OutputFilePath = _stripComments.InputFilePath;
            _stripComments.OutputFileName = "New.Web.config";

            bool result = _stripComments.Execute();
            Assert.IsFalse(result);
        }

        [TestMethod]
        public void TestThatErrorThrowsWhenFileIsEmpty()
        {
            _stripComments.InputFilePath =
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Substring(6);
            _stripComments.InputFileName = "Empty.Web.configs";

            _stripComments.OutputFilePath = _stripComments.InputFilePath;
            _stripComments.OutputFileName = "New.Web.config";

            bool result = _stripComments.Execute();
            Assert.IsFalse(result);
        }

        [TestMethod]
        public void TestThatNoErrorThrows()
        {
            _stripComments.InputFilePath =
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Substring(6);
            _stripComments.InputFileName = "Web.config";

            _stripComments.OutputFilePath = _stripComments.InputFilePath;
            _stripComments.OutputFileName = "New.Web.config";

            bool result = _stripComments.Execute();
            Assert.IsTrue(result);
        }
    }
}